<?php

/*
* Update the value (points) of all pile divs.
*
* @header project_name Name of the project
* @header grandpa Div ID	 
* @header divVal Selected option in the div
* 
* @return mysql_error()
*          if there was an error updating the database
* @return "success"
*          upon success
*/

require_once("session.php");
require_once("connect_to_database.php");

$project = $_POST['project_name'];
$grandpa = $_POST['grandpa'];
$val = $_POST['divVal'];

// Update div with the selected option
if(val == ""){
	$query = sprintf("UPDATE points SET divVal='NULL' WHERE projectName='%s' AND divID='%s'",$project,$grandpa);
	$result = mysql_query($query);

	if(!$result){
		error_log($query.mysql_error());
		die(mysql_error());
	}
	echo("success");
}

else{
	$query = sprintf("UPDATE points SET divVal='%s' WHERE projectName='%s' AND divID='%s'", $val,$project,$grandpa);
	$result = mysql_query($query);

	if(!$result){
		error_log($query.mysql_error());
		die(mysql_error());
	}
	echo("success");
}

?>